﻿using System;
using System.Data;
using System.Web.UI.WebControls;

public partial class Menu_Menu : System.Web.UI.Page
{
    int i = 1;
    public int j = 0;
    Datautility DU = new Datautility();
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
            DataSet DS = new DataSet();
            DS.ReadXml(Server.MapPath("~/App_Data/Menu.xml"));
             DataTable dtcomp = DU.getdatausingprocedure("usp_get_acc_company_maintain_options");
             if (dtcomp.Rows.Count > 0)
             {
                 if (dtcomp.Rows[0]["IsAccEnabled"].ToString().Equals("False") || dtcomp.Rows[0]["IsAccEnabled"].ToString().Equals(string.Empty))
                 {
                     DS.Tables[0].Rows[3].Delete();
                 }
                 if (dtcomp.Rows[0]["IsInvcEnabled"].ToString().Equals("False") || dtcomp.Rows[0]["IsInvcEnabled"].ToString().Equals(string.Empty))
                 {
                     DS.Tables[0].Rows[4].Delete();
                 }

                 if (dtcomp.Rows[0]["IsInvrEnabled"].ToString().Equals("False") || dtcomp.Rows[0]["IsInvrEnabled"].ToString().Equals(string.Empty))
                 {
                     DS.Tables[0].Rows[2].Delete();
                 }
                 //string[] booksFromDate = Convert.ToDateTime(dtcomp.Rows[0]["booksfromdate"].ToString()).ToShortDateString().Split('/');
                 Session["booksfromdate"] = dtcomp.Rows[0]["booksfromdate"].ToString();
                 //string[] booksEndDate = Convert.ToDateTime(dtcomp.Rows[0]["booksenddate"].ToString()).ToShortDateString().Split('/');
                 Session["booksenddate"] = dtcomp.Rows[0]["booksenddate"].ToString();
             }


            ParentRepeater.DataSource = DS;
            ParentRepeater.DataBind();

            //DataTable dtcomp = DU.getdatausingprocedure("usp_get_acc_company_maintain_options");
            //if (dtcomp.Rows.Count>0)
            //{
            //    //while (rdrcomp.Read())
            //    //{
            //        Session["IsAccEnabled"] = dtcomp.Rows[0]["IsAccEnabled"].ToString();
            //        Session["IsInvcEnabled"] = dtcomp.Rows[0]["IsInvcEnabled"].ToString();
            //        Session["IsInvrEnabled"] = dtcomp.Rows[0]["IsInvrEnabled"].ToString();
            //    //}
            //}
        }
    }

    protected void ParentRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {

        RepeaterItem item = e.Item;
        if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater ChildRepeater = (Repeater)item.FindControl("ChildRepeater");
            ChildRepeater.ItemDataBound += new RepeaterItemEventHandler(ChildRepeater_ItemDataBound);
            DataRowView drv = (DataRowView)item.DataItem;
            DataView dview = drv.CreateChildView("Menu_SubMenu");
            dview.Sort = "text";

            ChildRepeater.DataSource = dview;// here u can also bind the Child Repeater with DataTable like 
            //ChildRepeater.DataSource = datatableName;
            ChildRepeater.DataBind();
        }
    }

    protected void ChildRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HyperLink hlnk = (HyperLink)e.Item.FindControl("hy1");
            hlnk.Attributes["rel"] = "anylinkmenu" + (i++);
        }
    }
  
}
